package com.xcmg.manage.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.xcmg.manage.entity.Staff;
import com.xcmg.manage.feign.EmployeeFeignService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Resource
    EmployeeFeignService employeeFeignService;

    @RequestMapping("/addStaff")
    public String addStaff(){
        int sa=employeeFeignService.addStaff();
        System.out.println("添加1位员工");
        return "成功添加"+sa+"员工";

    }

    @RequestMapping("/getStaff")
    public Staff printStaff(){
        int id=1;
        Staff sa=employeeFeignService.getStaff(id);
        System.out.println(sa.getName()+"8060");
        return sa;
    }

    @RequestMapping("/deleteStaff/{id}")
    public void deleteStaffById(@PathVariable("id") int id){

        employeeFeignService.deleteStaffById(id);

    }

    @RequestMapping("/update")
    public void updateStaffById(){
        int id=1;
        Staff staff=employeeFeignService.getStaff(id);
        staff.setName("lixi2");
        employeeFeignService.updateStaffById(staff);
        System.out.println("已经修改"+id+"的信息为"+staff.getName());
    }


    @SentinelResource(value = "/manage/testManage",blockHandler = "handler_TestManage")
    @RequestMapping("/testManage")
    public String test(){

        String s=employeeFeignService.testSentinel();
        System.out.println("manageController");
        return s+"   manageControllerResult";
    }


    public String handler_TestManage(BlockException e){

        return "您的手速太快";
    }


}